package com.cx.controller;

import com.cx.common.ApiReturn;
import com.cx.pojo.Body;
import com.cx.pojo.Chassis;
import com.cx.service.BodyService;
import com.cx.service.ChassisService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("body")
@CrossOrigin//跨域
public class BodyController {

    @Autowired
    BodyService bodyService;

    //添加车身参数
    @RequestMapping("insertBody")
    @ResponseBody
    public ApiReturn insertBody(Body body){
        int rows = bodyService.insert(body);
        if (rows<1){
            return ApiReturn.error("添加失败");
        }
        return  ApiReturn.success("添加成功");
    }

    //修改车身参数
    @RequestMapping("updateBody")
    @ResponseBody
    public ApiReturn updateBody(Body body){
        int rows = bodyService.updateByPrimaryKey(body);
        if (rows<1){
            return ApiReturn.error("修改失败");
        }
        return ApiReturn.success("修改成功");
    }

    //删除车身参数
    @RequestMapping("deleteBody")
    @ResponseBody
    public ApiReturn deleteBody(Integer bodyId) {
        int rows = bodyService.deleteByPrimaryKey(bodyId);
        if (rows < 1) {
            return ApiReturn.error("删除失败");
        }
        return ApiReturn.success("删除成功");
    }

    //根据id查询车身参数
    @RequestMapping("selectBodyById")
    @ResponseBody
    public ApiReturn selectBodyById(Integer bodyId) {
        Body bodyInfo = bodyService.selectByPrimaryKey(bodyId);
        if (bodyInfo != null) {
            return ApiReturn.success("车身参数数据详情",bodyInfo);
        }
        return ApiReturn.error("未获取该车身参数数据详情");
    }

    //查询所有车身参数
    @RequestMapping("selectAllBody")
    @ResponseBody
    public ApiReturn selectAllBody(Body body) {
        PageInfo<Body> page = bodyService.selectAllBody(body);
        if (page.getList() != null) {
            return ApiReturn.success("所有车身参数数据",page);
        }
        return ApiReturn.error("无数据");
    }
}
